Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve impersonation logic #26891

Merged
merged 11 commits into from
Dec 16, 2024
Merged

Conversation

benjackwhite
Copy link
Contributor

@benjackwhite benjackwhite commented Dec 13, 2024

Problem

Enough discussion around the limits of our current impersonation logic - lets improve it

Changes

Manual refreshing

2024-12-13 10 40 58

Automatic logout check

2024-12-13 10 41 17

  • Added a new setting for "IDLE_TIMEOUT" which is extended on each request
  • Improved the banner to have a refresh button and to automatically check for access once the countdown hits
  • Changes the idle timeout to 30 mins and the total timeout to 2 hours.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?

  • Automated tests and tried it out myself a bunch

Copy link
Contributor

github-actions bot commented Dec 13, 2024

Size Change: 0 B

Total Size: 1.11 MB

ℹ️ View Unchanged
Filename Size
frontend/dist/toolbar.js 1.11 MB

compressed-size-action

@@ -677,7 +677,19 @@ def get_impersonated_session_expires_at(request: HttpRequest) -> Optional[dateti

init_time = get_or_set_session_cookie_created_at(request=request)

return datetime.fromtimestamp(init_time) + timedelta(seconds=settings.IMPERSONATION_TIMEOUT_SECONDS)
last_activity_time = request.session.get(settings.IMPERSONATION_COOKIE_LAST_ACTIVITY_KEY, init_time)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking out loud

a mini google suggests the default session engine signs the cookie content so a naughty person can't send their own init time here

(and anyway it would only be useful to an attacker if they had control of an impersonated session which would mean even if you could edit this then it wouldn't matter since they have impersonation)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're confusing session and cookies. The cookie just has a sessionid. The session is loaded in django from the DB. So here it is modifying the session DB entry, nothing from the user.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, bad googling from me 👍

Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@pauldambra
Copy link
Member

survey test fixes in #26892

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

2 snapshot changes in total. 0 added, 2 modified, 0 deleted:

  • chromium: 0 added, 2 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@posthog-bot
Copy link
Contributor

📸 UI snapshots have been updated

1 snapshot changes in total. 0 added, 1 modified, 0 deleted:

  • chromium: 0 added, 1 modified, 0 deleted (diff for shard 2)
  • webkit: 0 added, 0 modified, 0 deleted

Triggered by this commit.

👉 Review this PR's diff of snapshots.

@benjackwhite benjackwhite merged commit f8c867f into master Dec 16, 2024
96 checks passed
@benjackwhite benjackwhite deleted the feat/extended-impersonation branch December 16, 2024 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants